package com.leetcode2;

import com.Util.ProduceTree;
import com.structure.TreeNode;

public class Index337rob {
	
	public static void main(String[] args) {
		String s = "[3,2,3,null,3,null,1]";
		TreeNode root = ProduceTree.stringToTreeNode(s);
		Index337rob rob = new Index337rob();
		int res = rob.rob(root);
		System.out.println(res);
	}
	public int rob(TreeNode root) {
        int ans = steal(root.left,root);
        int ans2 = steal(root.right,root);
        return ans+ans2+root.val;
    }

    public int steal(TreeNode node,TreeNode parent){
        if(node == null) return 0;
        int left = steal(node.left,node);
        int right = steal(node.right,node);
        if(left+right+parent.val >= node.val)
            return left+right;
        else
            return node.val;
    }
}
